Skip to content

termios: Add TIOCSHALFD for ioctl() for enabling half-duplex uart#461

Open
olaf-czerwinski-phoenix-systems wants to merge 1 commit intomasterfrom
oczerwinski/uart-half-duplex-stm32n6
Open

termios: Add TIOCSHALFD for ioctl() for enabling half-duplex uart#461
olaf-czerwinski-phoenix-systems wants to merge 1 commit intomasterfrom
oczerwinski/uart-half-duplex-stm32n6

Conversation

@olaf-czerwinski-phoenix-systems

TASK: PP-428

Description

Add TIOCSHALFD for ioctl() for enabling half-duplex uart

Motivation and Context

Allows enabling half-duplex mode (for now supported in stm32n6 only).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: stm32n6.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist
Copy link

Summary of Changes

Hello @olaf-czerwinski-phoenix-systems, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new ioctl command, TIOCSHALFD, to the termios.h header. This addition provides the necessary interface for applications to enable half-duplex UART functionality, specifically noted to be supported on stm32n6 platforms. The change expands the system's capability to manage serial communication modes.

Highlights

  • New ioctl command: Added the TIOCSHALFD macro to include/termios.h, enabling the configuration of half-duplex UART mode.
Changelog
  • include/termios.h
    • Added TIOCSHALFD macro for half-duplex UART control.
Activity
  • The author, olaf-czerwinski-phoenix-systems, created this pull request.
  • The change introduces a new feature.
  • Manual testing was performed on stm32n6 to verify the functionality.
  • The author confirmed that the changes generate no new compilation warnings.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new ioctl command, TIOCSHALFD, to enable half-duplex mode for UART. The implementation is straightforward and adds needed functionality. I have one suggestion regarding the API design to improve consistency with existing ioctl commands in the codebase by considering the addition of a corresponding 'get' command and adjusting the command numbering accordingly.

#define TIOCSWINSZ _IOW('t', 0x14, struct winsize)
#define TIOCNOTTY _IO('t', 0x22)
#define TIOCGSID _IOR('t', 0x29, pid_t)
#define TIOCSHALFD _IOV('t', 0x2a, int)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For API consistency and to follow conventions in this file (e.g., TIOCGPGRP/TIOCSPGRP), it is good practice to provide a corresponding 'get' operation for a 'set' operation. The existing ioctl commands often follow a GET=N, SET=N+1 numbering scheme. To align with this pattern, I suggest using 0x2b for TIOCSHALFD and reserving 0x2a for a TIOCGHALFD. The 'get' command could be added now or in a follow-up PR and would likely look like this:

#define TIOCGHALFD _IOR('t', 0x2a, int)
Suggested change
#define TIOCSHALFD _IOV('t', 0x2a, int)
#define TIOCSHALFD _IOV('t', 0x2b, int)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda agree + perhaps move non-standard ones higher, e.g. 0x80 (so 0x80 + 0x81 combo)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@olaf-czerwinski-phoenix-systems olaf-czerwinski-phoenix-systems added the enhancement New feature or request label Mar 2, 2026
@olaf-czerwinski-phoenix-systems olaf-czerwinski-phoenix-systems force-pushed the oczerwinski/uart-half-duplex-stm32n6 branch from feba061 to 07ba8c4 Compare March 18, 2026 15:39
Copy link
Member

@agkaminski agkaminski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @nalajcie is this ok to add such custom ioctl? (Imho ok)

@jmaksymowicz
Copy link
Contributor

We'll probably have to add a custom ioctl, I don't think there are is anything standard that does exactly what is required here - the closest would be TIOCSRS485

@agkaminski
Copy link
Member

We'll probably have to add a custom ioctl, I don't think there are is anything standard that does exactly what is required here - the closest would be TIOCSRS485

Yes, alternative approach I see is to add it to the stm32 specific header. But libtty has to be aware anyway, so the current solution is better

Copy link
Member

@nalajcie nalajcie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • invalid commit message title (missing prefix)
  • invalid 64bit impl (breaks riscv64 build)
  • either invalid impl or declaration (impl takes int**, not int)
  • implementation returns success even if half-duplex is not supported in uart driver

I'm ok with adding this functionality as a custom IOCTL(s), but please make the change sensible.

@olaf-czerwinski-phoenix-systems olaf-czerwinski-phoenix-systems force-pushed the oczerwinski/uart-half-duplex-stm32n6 branch from 07ba8c4 to 5fe668c Compare March 19, 2026 11:18
@olaf-czerwinski-phoenix-systems olaf-czerwinski-phoenix-systems changed the title termios.h: Add TIOCSHALFD for ioctl() for enabling half-duplex uart termios: Add TIOCSHALFD for ioctl() for enabling half-duplex uart Mar 19, 2026
@github-actions
Copy link

github-actions bot commented Mar 19, 2026

Unit Test Results

9 553 tests  ±0   8 961 ✅ ±0   55m 39s ⏱️ + 3m 7s
  591 suites ±0     592 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 5fe668c. ± Comparison against base commit 74852cb.

♻️ This comment has been updated with latest results.

@olaf-czerwinski-phoenix-systems
Copy link
Author

olaf-czerwinski-phoenix-systems commented Mar 25, 2026

  • invalid commit message title (missing prefix)

    • invalid 64bit impl (breaks riscv64 build)

    • either invalid impl or declaration (impl takes int**, not int)

    • implementation returns success even if half-duplex is not supported in uart driver

I'm ok with adding this functionality as a custom IOCTL(s), but please make the change sensible.

@nalajcie I think that all issues should be addressed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants